package yzbx.personalwebsite.webSocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

/**
 * {@code @Author} zxm
 * {@code @Description} ws配置类
 * {@code @Date} 2024/11/15/13:21
 * {@code @Version} 1.0
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {


    private final WebSocketTalk webSocketTalk;

    @Autowired
    WebSocketConfig(WebSocketTalk webSocketTalk) {
        this.webSocketTalk = webSocketTalk;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketTalk, "/talk")
                .addInterceptors(new HttpSessionHandshakeInterceptor())
                .setAllowedOrigins("*");
    }
}
